'use strict';
import * as Koa from 'koa';
import { router, prefix } from '../middleware/router';
import { menuService } from '../service/menu';
import { response } from '../middleware/result';

/** 菜单API对象 */
@prefix('menu')
class MenuController {
    @router('/create',{method: 'post'})
    async create(ctx: Koa.Context) {
        let result = await menuService.create(ctx.request.body);
        response(ctx, result);
    }
    @router('/update',{method: 'post'})
    async update(ctx: Koa.Context) {
        let result = await menuService.update(ctx.request.body);
        response(ctx, result);
    }
    @router('/delete/:id')
    async delete(ctx: Koa.Context) {
        let result = await menuService.delete(ctx.params.id);
        response(ctx, result);
    }
    @router('/queryById/:id')
    async queryById(ctx: Koa.Context) {
        let result = await menuService.queryById(ctx.params.id);
        response(ctx, result);
    }
    /** 获取菜单树 */
    @router('/queryTree')
    async queryTree(ctx: Koa.Context) {
        let result = await menuService.queryTree();
        response(ctx, result);
    }
}